home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / By the Book / Mac C Primer V2 / 6.1 - MyStarter / CStarterPane.c < prev    next >
Text File  |  1992-04-10  |  2KB  |  104 lines

  1. /************************************************************/
  2. /*                                                            */
  3. /*    CStarterPane Code from Chapter Six of                    */
  4. /*                                                            */
  5. /*        *** The Macintosh Programming Primer ***            */
  6. /*                                                            */
  7. /*    Copyright 1990, Dave Mark                                */
  8. /*                                                            */
  9. /*    This program demonstrates specific Mac programming        */
  10. /*    techniques.                                                */
  11. /*                                                            */
  12. /************************************************************/
  13.  
  14. #include "CStarterPane.h"
  15. #include "CDragPane.h"
  16. #include "CMouse.h"
  17.  
  18.  
  19. /****************************************  IStarterPane  */
  20.  
  21. void CStarterPane::IStarterPane( CView *anEnclosure, CBureaucrat *aSupervisor,
  22.                             short aWidth, short aHeight,
  23.                             short aHEncl, short aVEncl,
  24.                             SizingOption aHSizing, SizingOption aVSizing )
  25. {
  26.     CPanorama::IPanorama( anEnclosure, aSupervisor,
  27.                             aWidth, aHeight,
  28.                             aHEncl, aVEncl,
  29.                             aHSizing, aVSizing );
  30.                             
  31.     GetDateTime( (unsigned long *)&randSeed );
  32.                             
  33.     SetWantsClicks( TRUE );
  34. }
  35.  
  36.  
  37. /******************************** DoClick *********/
  38.  
  39. void CStarterPane::DoClick( Point hitPt, short modifierKeys, long when )
  40. {
  41.     int            width, height, patNum;
  42.     CDragPane    *myDragPane;
  43.     
  44.     width = Randomize( MAX_PANE_SIZE );
  45.     height = Randomize( MAX_PANE_SIZE );
  46.     patNum = Randomize( NUM_PATS );
  47.     
  48.     myDragPane = new( CDragPane );
  49.     myDragPane->IDragPane( hitPt, height, width,
  50.                             patNum, this, this );
  51. }
  52.  
  53.  
  54. /******************************** AdjustCursor *********/
  55.  
  56. void CStarterPane::AdjustCursor( Point where, RgnHandle mouseRgn )
  57. {
  58.     SetCursor( *GetCursor( plusCursor ) );
  59. }
  60.  
  61.  
  62. /******************************** DoDrag *********/
  63.  
  64. void CStarterPane::DoDrag( int objWidth, int objHeight,
  65.             Point hitPt, Rect startLocation, Rect *endLocation )    
  66. {
  67.     CMouse        *aMouseTask;
  68.     LongRect        boundsRect;
  69.     Point        p;
  70.     LongPt        longP;
  71.     
  72.     gIsScrolling = TRUE;
  73.     
  74.     boundsRect = bounds;
  75.     
  76.     aMouseTask = new( CMouse );
  77.     
  78.     aMouseTask->IMouse( NO_UNDO_STRING, objWidth,
  79.             objHeight, hitPt, startLocation, this );
  80.             
  81.     Prepare();
  82.     
  83.     GetMouse( &p );
  84.     QDToLongPt( p, &longP );
  85.     TrackMouse( aMouseTask, &longP, &boundsRect );
  86.     
  87.     gIsScrolling = FALSE;
  88.     
  89.     aMouseTask->GetLocation(endLocation);    /* Update endLocation */
  90.     
  91.     Refresh();
  92. }
  93.  
  94.  
  95. /******************************** Randomize *********/
  96.  
  97. Randomize( int range )
  98. {
  99.     long    rawResult;
  100.     
  101.     rawResult = Random();
  102.     if ( rawResult < 0 ) rawResult *= -1;
  103.     return( (rawResult * range) / 32768 );
  104. }